home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / prog / graphics / seg_arrange.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  2.0 KB  |  120 lines

  1. #include <LEDA/sweep_segments.h>
  2. #include <LEDA/subdivision.h>
  3. #include <LEDA/segment.h>
  4. #include <LEDA/window.h>
  5.  
  6.  
  7.  
  8.  
  9. void   show_face(subdivision<int>& G, face f, window& W)
  10. { list<node> L = G.adj_nodes(f);
  11.   list<point> P;
  12.   node v;
  13.   forall(v,L) P.append(G[v]);
  14.   W.draw_filled_polygon(P,orange);
  15. }
  16.  
  17.  
  18. main()
  19. {
  20.  
  21.   window W;
  22.  
  23.   W.init(0,1000,0);
  24.  
  25.   W.set_node_width(3);
  26.   W.set_line_width(2);
  27.  
  28.   panel P("Arrangement of line segments");
  29.  
  30.   P.text_item("This program computes the subdivision defined by the "); 
  31.   P.text_item("arrangement of a list of straight line segments. Use ");
  32.   P.text_item("the left button to insert a sequence of segments and ");
  33.   P.text_item("terminate the input by clicking the right button. Now");
  34.   P.text_item("you can input query points with the left button. For ");
  35.   P.text_item("each point p the face of the arrangment containing p ");
  36.   P.text_item("is computed and displayed. Terminate the program by  "); 
  37.   P.text_item("pressing the right mouse key.                        ");
  38.   P.text_item("                                                     ");
  39.  
  40.   P.button("continue");
  41.  
  42.   P.open();
  43.  
  44.  
  45.  
  46.   list<segment> seglist1,seglist2;
  47.   segment s;
  48.  
  49.   while ( W >> s ) 
  50.   { W << s;
  51.     seglist1.append(s);
  52.    }
  53.  
  54.   GRAPH<point,int> G;
  55.  
  56.  
  57.   cout << "Computing subdivision.\n";
  58.  
  59.  
  60.   SWEEP_SEGMENTS(seglist1,seglist2,G);
  61.  
  62.   W.clear(); 
  63.  
  64.   // Draw Subdivision
  65.  
  66.   edge e;
  67.   forall_edges(e,G)
  68.   W.draw_segment(G[source(e)], G[target(e)]);
  69.  
  70.  
  71.  
  72.   cout << "Constructing search structure\n";
  73.  
  74.  
  75.   // insert reverse edges
  76.  
  77.   list<edge> L = G.all_edges();
  78.   forall(e,L) G.new_edge(target(e),source(e),G[e]);
  79.  
  80.  
  81.   // sort edges counter-clockwise
  82.  
  83.   edge_array<double> angle(G);
  84.  
  85.   forall_edges(e,G)
  86.   { segment s(G[source(e)],G[target(e)]);
  87.     angle[e] = s.angle();
  88.    }
  89.  
  90.   G.sort_edges(angle);
  91.  
  92.  
  93.   // Create Subdivision
  94.  
  95.   subdivision<int> S(G);
  96.  
  97.  
  98.  
  99.   W.message("Give query points!");
  100.  
  101.  
  102.  
  103.  
  104.   // Locate points
  105.  
  106.   W.set_mode(xor_mode);
  107.  
  108.   point p;
  109.   face  f=nil;
  110.  
  111.   while (W >> p)
  112.   { if (f) show_face(S,f,W);
  113.     f = S.locate_point(p);
  114.     show_face(S,f,W);
  115.    }
  116.  
  117.  
  118.   return 0;
  119. }
  120.